

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Header
#pragma once
#include <CEMAPI.h>
#include "SyncSettings.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


extern IMAPIFolder* m_pInbox;
extern IMAPIFolder* m_pOutbox;
extern IMAPIFolder* m_pSentbox;

extern IMAPIFolder* m_pFxNumBox;

extern IMsgStore* m_pMsgStore;
extern IMailSyncCallBack* m_pCallback;
//extern HANDLE hConn;

HRESULT RecvMsg(PCWSTR pwzContent, PCWSTR pwzSenderName = L"Fetion", PCWSTR pwzSenderPhone = TEXT("10000"), LPFILETIME pftDeliveryTime = NULL);
HRESULT DelMsg(PCWSTR pwzSenderNo,PCWSTR pwzSender = NULL,bool isContact = false);
bool EstablishConnect();
bool CloseConnect();
bool IsConnect();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class SyncHandler
class SyncHandler: public IMailSyncHandler, public IMAPIAdviseSink, public SyncSettings
{
protected:
	ULONG m_uAdviseSink;


public:
	// Constructor & destructor
	SyncHandler();
	~SyncHandler();

public:
	// IMailSyncHandler
	MAPIMETHOD(Install)(PCWSTR pwzProfile, PCWSTR pwzInServer, PCWSTR pwzOutServer, GUID* pidNetwork);
	MAPIMETHOD(UnInstall)();

	MAPIMETHOD(Initialize)(IMailSyncCallBack* pCallback, PCWSTR pwzProfile, IMsgStore* pMsgStore);
	MAPIMETHOD(Uninitialize)();
	MAPIMETHOD(ShutDown)(DWORD dwReserved = 0);

	MAPIMETHOD(Connect)(DWORD dwReserved = 0, SYNCCREDENTIALS* pCred = NULL);
	MAPIMETHOD(Disconnect)(DWORD dwReserved = 0);

	MAPIMETHOD(Synchronize)(MAILSYNCREQUEST* pReq);

	MAPIMETHOD(DoProperties)(HWND hParent);
	MAPIMETHOD(GetCapability)(PCWSTR pwzName, LPSPropValue pVal);
	MAPIMETHOD(SetCapability)(PCWSTR pwzName, LPSPropValue pVal);
	MAPIMETHOD(DecodeEvent)(TRANSPORTEVENT* pEvt, PWSTR* ppwzEvent);
	MAPIMETHOD(GetFolderHierarchy)(FOLDERNODE** ppRootNode);
	MAPIMETHOD(SetFolderOptions)(LPMAPIFOLDER pFolder, FOLDERNODE* pNode, FOLDEROPTIONS fOpts, LPSPropValue pVal);

public:
	// IMAPIAdviseSink
	MAPIMETHOD_(ULONG, OnNotify)(ULONG cNotify, LPNOTIFICATION pNotify);

public:

	BOOL Send(PCTSTR ptzTo, PCTSTR ptzContent);

	HRESULT SetStatusText(LPCWSTR wzStatusText)
	{
		SYNCPROGRESSITEM item = {0};
		item.cbSize = sizeof(item);
		item.mask = SYNCPROGRESSITEM_STATUSTEXT;
		item.pwszStatusText = wzStatusText;
		HRESULT hResult = m_pCallback->Progress(m_tzProfile, &item);
		return hResult;
		//m_pCallback->DisplayMessageBox(m_tzProfile, UStrGet(IDS_SysMsg), UStrGet(uStrID), MB_ICONWARNING);
	}

/*
	HRESULT SetStatusText(UINT uStrID){
		return SetStatusText(UStrGet(uStrID));
	}
*/
protected:
	HRESULT SyncOutbox();
	HRESULT SendMsg(LPMESSAGE pMsg);

};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

typedef struct _SMS_Filter
{
	CStr Content;
	int idx;
	_SMS_Filter * next;
} SMS_Filter;
extern int MaxSmsFilterIdx;

extern SMS_Filter * BlockSMS;

bool IsDirty(CStr PhoneNo,CStr Content);
bool GetDirtyList();
